<template>
  <div class="musicList">
    <div class="musicTop">
      <div class="title">歌单推荐</div>
      <div class="more">待开发</div>
    </div>
    <div class="musicContent">
      <van-swipe
        :loop="false"
        :width="150"
        class="my-swipe"
        :show-indicators="false"
      >
        <van-swipe-item v-for="item in state.musicList" :key="item">
          <router-link :to="{ path: '/itemMusic', query: { id: item.id } }">
            <img :src="item.picUrl" alt="" />
            <span class="name"> {{ item.name }} </span>
          </router-link>
        </van-swipe-item>
      </van-swipe>
    </div>
  </div>
</template>

<script>
import { getMusicList } from "@/request/api/home";
import { reactive, onMounted } from "vue";
export default {
  // data() {  // vue2写法
  //   return {
  //     musicList: [],
  //   };
  // },
  // methods: {
  //   async getGedam() {
  //     let res = await getMusicList();
  //     console.log(res);
  //     this.musicList = res.data.result;
  //   },
  // },
  // mounted() {
  //   this.getGedam();
  // },
  setup() {
    // vue3组合式api写法
    const state = reactive({
      musicList: [],
    });
    onMounted(async () => {
      let res = await getMusicList();
      console.log(res);
      state.musicList = res.data.result;
    });
    return { state };
  },
};
</script>
<style lang="less">
.musicList {
  width: 100%;
  height: 5rem;
  padding: 0.2rem;
  .musicTop {
    width: 100%;
    height: 0.6rem;
    display: flex;
    justify-content: space-between;
    margin-bottom: 00.2rem;
    .title {
      font-size: 0.4rem;
      font-weight: 600;
    }
    .more {
      width: 20%;
      height: 100%;
      font-size: 0.2rem;
      border: 1px solid;
      text-align: center;
      line-height: 0.6rem;
      border-radius: 0.4rem;
    }
  }
  .musicContent {
    width: 100%;
    height: 4rem;
    .my-swipe {
      height: 100%;
      img {
        width: 100%;
        height: 70%;
      }
      .name {
        width: 100%;
        height: 30%;
        font-size: 0.15rem;
        font-weight: 200;
      }
    }
  }
}
</style>
